#!/bin/sh
# postinst script for upp
#
# see: dh_installdeb(1)

set -e

# summary of how this script can be called:
#        * <postinst> `configure' <most-recently-configured-version>
#        * <old-postinst> `abort-upgrade' <new version>
#        * <conflictor's-postinst> `abort-remove' `in-favour' <package>
#          <new-version>
#        * <postinst> `abort-remove'
#        * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
#          <failed-install-package> <version> `removing'
#          <conflicting-package> <version>
# for details, see http://www.debian.org/doc/debian-policy/ or
# the debian-policy package

create_bm(){
    echo "Configuring build method $2 for $1"
    mkdir -p "/usr/share/upp"
    cat > "/usr/share/upp/$2.bm" << EOF
BUILDER = "GCC";
COMPILER = "$1";
DEBUG_INFO	= "2";
DEBUG_BLITZ	= "1";
DEBUG_LINKMODE	= "1";
DEBUG_OPTIONS	= "-O0";
DEBUG_FLAGS	= "";
RELEASE_BLITZ		= "0";
RELEASE_LINKMODE	= "1";
RELEASE_OPTIONS		= "-O3 -ffunction-sections -fdata-sections";
RELEASE_SIZE_OPTIONS	= "-Os -finline-limit=20 -ffunction-sections -fdata-sections";
RELEASE_FLAGS	= "";
RELEASE_LINK	= "-Wl,--gc-sections";
DEBUGGER	= "gdb";
PATH		= "";
INCLUDE = "/usr/include/freetype2;/usr/include/gtk-2.0;/usr/include/glib-2.0;/usr/lib/glib-2.0/include;/usr/lib/gtk-2.0/include;/usr/include/cairo;/usr/include/pango-1.0;/usr/include/atk-1.0;/usr/include/gdk-pixbuf-2.0;/usr/lib/i386-linux-gnu/glib-2.0/include;/usr/lib/x86_64-linux-gnu/glib-2.0/include;/usr/lib/i386-linux-gnu/gtk-2.0/include;/usr/lib/x86_64-linux-gnu/gtk-2.0/include;/usr/include/gtk-3.0/gdk"
LIB = "/usr/X11R6/lib";
REMOTE_HOST	= "";
REMOTE_OS	= "";
REMOTE_TRANSFER	= "";
REMOTE_MAP	= "";
LINKMODE_LOCK	= "0";
EOF
    chmod 644 /usr/share/upp/$2.bm
}

case "$1" in
    configure)
        [ "`which g++ 2>/dev/null`" ] && create_bm "g++" "GCC" || true
        [ "`which clang++ 2>/dev/null`" ] && create_bm "clang++" "CLANG" || true
        for v in `seq 9 -1 3` 1 0; do
            [ "`which g++-4.$v 2>/dev/null`" ] && create_bm "g++-4.$v" "GCC4.$v" || true
        done
        [ "`ls /usr/share/upp/*.bm 2>/dev/null`" ] || create_bm "g++" "GCC"
    ;;

    abort-upgrade|abort-remove|abort-deconfigure)
        rm -f /usr/share/upp/*.bm
    ;;

    *)
        echo "postinst called with unknown argument \`$1'" >&2
        exit 1
    ;;
esac

# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

#DEBHELPER#

exit 0
